﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc; 
namespace AspNetMVCPractice.CustomAuthorize.WebExtensions
{
    public class CustomAuthorizeAttribute : AuthorizeAttribute
    {
        private readonly ImageResult requiredType;

        public CustomAuthorizeAttribute(ImageResult comparedWithType)
        {
            this.requiredType = comparedWithType;
        }

        internal bool PerformAuthorizeCore(System.Web.HttpContextBase httpContext) { return this.AuthorizeCore(httpContext); }

        protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            if (!httpContext.User.Identity.IsAuthenticated)
                return false; 

            using (IntexReptServBLClient client = new IntexReptServBLClient())
            {
                var calculatedAccountType = client.GetInfo(httpContext.User.Identity.Name);

                switch(this.requiredType.str0)
                {
                    case "A":
                        break;
                    default:
                        return base.AuthorizeCore(httpContext);
                }
            }
            return true;
        }
    }
}
